/**
 * AlexBasicInformationCollector.java created by zhangzhidong 
 * at 上午10:34:40 2016年5月23日
 */
package cn.edu.bjtu.alex;

import java.io.File;
import java.io.FileFilter;


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.shirdrn.document.preprocessing.api.Context;
import org.shirdrn.document.preprocessing.core.common.AbstractComponent;
/**
 * 
 * @author zhangzhidong<br>
 * comment generated at 2016年5月24日下午10:07:54<br>
 * 稍微修改用于过滤隐藏文件
 * @version 1.1
 *
 */
public class AlexBasicInformationCollector extends AbstractComponent  {
	
	private static final Log LOG = LogFactory.getLog(AlexBasicInformationCollector.class);
	
	public AlexBasicInformationCollector(final Context context) {
		super(context);
	}
	public void fire() {
		int totalDocCount = 0;
		String labels[] = context.getFDMetadata().getInputRootDir().list(this); 
		for(String label : labels) {
			context.getVectorMetadata().addLabel(label);
			LOG.info("Add label: label=" + label);
			File labelDir = new File(context.getFDMetadata().getInputRootDir(), label);
			File[] files = labelDir.listFiles(new FileFilter() {
				public boolean accept(File pathname) {
					return pathname.getAbsolutePath().endsWith(context.getFDMetadata().getFileExtensionName());
				}
			});
			context.getVectorMetadata().putLabelledTotalDocCount(label, files.length);
			LOG.info("Put document count: label= " + label + ", docCount=" + files.length);
			totalDocCount += files.length;
		}
		LOG.info("Total documents: totalCount= " + totalDocCount);
		context.getVectorMetadata().setTotalDocCount(totalDocCount);
	}
	


}
